//
//  HKBaseModuleNavController.m
//  HKUtilities
//
//  Created by 胡锦涛 on 2018/10/30.
//  Copyright © 2018 胡锦涛. All rights reserved.
//

#import "HKLibBaseNavController.h"

@interface HKLibBaseNavController ()
@property (nonatomic, strong) UIBarButtonItem * backItem ;
@end

@implementation HKLibBaseNavController

- (instancetype)initWithBackItem:(UIBarButtonItem*)backItem
{
    self = [super init];
    if (self) {
        self.backItem = backItem;
    }
    return self;
}
///设置NavBar属性
- (void)hk_setNavBar:(NSDictionary*)params {
    CGFloat font;
    UIColor *bgColor;
    UIColor *foregroundColor;
    if (params == nil) {
        font = 17;
        foregroundColor = [UIColor whiteColor];
        bgColor = [UIColor whiteColor];
    }else {
        font = [params[@"font"] floatValue];
        foregroundColor = params[@"foregroundColor"];
        bgColor = params[@"bgColor"];
    }
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:font]; // 字体大小
    attrs[NSForegroundColorAttributeName] = foregroundColor; // 颜色
    //self.navigationBar.tintColor = [UIColor whiteColor];
    UINavigationBar *naviBar = [UINavigationBar appearance];
    naviBar.barTintColor = bgColor;
    naviBar.tintColor = [UIColor whiteColor];
    [naviBar setTitleTextAttributes:attrs];
    // 解决iOS11界面缩放后导航栏空出状态栏的空隙的问题 方法1
    //[naviBar setBackgroundImage:[UIImage imageNamed:@"yitiji_date_nav_bg"] forBarMetrics:UIBarMetricsDefault];
}

/// push到TabBarController
- (void)pushToTabBar:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] init];
    // 隐藏tabbar
    viewController.hidesBottomBarWhenPushed = NO;
    [super pushViewController:viewController animated:animated];
}

/// 可以在这个方法中拦截所有push进来的控制器
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // 如果push进来的不是第一个控制器
    if (self.childViewControllers.count > 0) {
        
        viewController.navigationItem.leftBarButtonItem = self.backItem;
        // 隐藏tabbar
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}

-(void)hk_pop{
    [self popViewControllerAnimated:YES];
}

-(void)hk_popAll{
    [self popToRootViewControllerAnimated:YES];
}

- (void)hk_push:(UIViewController *)child{
    [self pushViewController:child animated:YES];
}

- (UIViewController *)childViewControllerForStatusBarStyle{
    return self.topViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
@end
